/**
 * 封装show图片，依靠weui，JQ
 */
(function ($){
	var showPicture,pictureId,containerId,_this;
	
	_this = this;
	
	showPicture = (function (){
		function showPicture(){}
		
		showPicture.prototype.init_showPicture = function (options){
			//图片的ID
			if(options.pictureId == null){
				throw new Error("pictureId 为空!");
			}
			_this.pictureId = $('#'+options.pictureId);

			$('body').append('<div class="weui-mask"></div>');
			$('.weui-mask').addClass('weui-animate-fade-in');
			
			//容器ID
			if(options.containerId != null){
				document.getElementById(options.containerId).style.overflow = 'hidden';
			}
			
			_this.pictureId.show();
			_this.pictureId.addClass('weui-animate-fade-in').on('animationend webkitAnimationEnd', function () {
				_this.pictureId.off('animationend webkitAnimationEnd');

				$('.weui-mask').on('touchend', function () {
					$('.weui-mask').addClass('weui-animate-fade-out');
					_this.pictureId.addClass('weui-animate-fade-out').on('animationend webkitAnimationEnd', function () {
						$('.weui-mask').remove();
						_this.pictureId.removeClass('weui-animate-fade-in weui-animate-fade-out');
						_this.pictureId.off('animationend webkitAnimationEnd');
						
						//容器ID
						if(options.containerId != null){
							document.getElementById(options.containerId).style.overflow = '';
						}
						
						_this.pictureId.hide();
					});
				});

				_this.pictureId.on('touchend', function () {
					$('.weui-mask').addClass('weui-animate-fade-out');
					_this.pictureId.addClass('weui-animate-fade-out').on('animationend webkitAnimationEnd', function () {
						$('.weui-mask').remove();
						_this.pictureId.removeClass('weui-animate-fade-in weui-animate-fade-out');
						_this.pictureId.off('animationend webkitAnimationEnd');
						
						//容器ID
						if(options.containerId != null){
							document.getElementById(options.containerId).style.overflow = '';
						}
						
						_this.pictureId.hide();
					});
				});
			});
		}

		return showPicture;
	})();

	
	/**
     * 添加到$.fn
     */
    $.extend($.fn,{showPicture:new showPicture()});
})($);